package godis

import (
	"context"
	"github.com/go-redis/redis/v8"
	"log"
	"sync"
)

var rdb *redis.Client

var redisClientOnce sync.Once

func Redis() *redis.Client {

	redisClientOnce.Do(func() {

		rdb = redis.NewClient(&redis.Options{
			Addr:     "192.168.56.102:6379",
			Password: "", // no password set
			DB:       0,  // use default DB
		})

		pong, err := rdb.Ping(context.Background()).Result()
		if err != nil {
			log.Fatal("redis connect failure")
		}

		log.Println(pong)

	})

	return rdb
}
